﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors.Repository;

namespace WmsApp.StaticData.Unity
{
    public abstract class BaseObserver
    {
        protected RepositoryItemLookUpEditBase LookUpEdit;
        protected string Name;
        protected ISubject Subject;
        protected ICanClosing CanClosing;

        public ICanClosing PCanClosing { get { return CanClosing; } }

        private EventHandler parentControlClosed;
        public event EventHandler ParentControlClosed
        {
            add
            {
                parentControlClosed += value;
            }
            remove
            {
                parentControlClosed -= value;
            }
        }

        public  BaseObserver(string name,ISubject subject,
             RepositoryItemLookUpEditBase lookUpEdit,ICanClosing canClosing)
        {
            this.CanClosing = canClosing;
            this.Name = name;
            this.Subject = subject;
            this.LookUpEdit = lookUpEdit;

            canClosing.FormClosing += (object sender, FormClosingEventArgs e) =>
                                    {
                                        if (parentControlClosed != null)
                                        {
                                            parentControlClosed(sender, new EventArgs());
                                        }
                                    };
           
        }

        public abstract void UpdateData();
    }
}
